<?php
include '../../init.php';
include DIR_CORE . 'mysql.php';
include DIR_CORE . 'Export.php';

//接收tx
$tx = $_GET['tx'];
switch ($tx) {
    case '单选题':  $type = "single"; $data = ['id','类型','题目','选项A','选项B','选项C','选项D','答案','添加时间']; break;
    
    case '多选题':  $type = "multiple"; $data = ['id','类型','题目','选项A','选项B','选项C','选项D','答案','添加时间']; break;
    
    case '判断题':  $type = "judge"; $data = ['id','类型','题目','答案','添加时间']; break;
    
    case '填空题': $type = "fill"; $data = ['id','类型','题目','答案','添加时间']; break;
    
    case '成绩单': $type = "score"; $data = ['id','姓名','分数','所用时间']; break;
    
    case '考试人员': $type = "user"; $data = ['id','姓名','password','加入时间']; break;
}
//echo $type;
//var_dump($data);
if ($type == "user") {
    $sql = "select id,name,password,created_time from $type where admin_id=3";
    $res = mysqli_query($link, $sql);
    //echo $sql;
    $list = array();
    while ($row = mysqli_fetch_row($link, $res)) {
        $list[] = $row;
    }
    //var_dump($list);
} else {
    $sql = "select * from $type";
    $res = mysqli_query($link, $sql);
    //echo $sql;
    $list = array();
    while ($row = mysqli_fetch_row($link, $res)) {
        $list[] = $row;
    }
    //var_dump($list);
}
$fileName = "沐水莲心-$tx";
$tmp = ["$tx"];
$export = new Export();
$result = $export->exportToCsv($data, $list, $fileName, $tmp);
